package cn.kgc.userprovider.controller;

import cn.kgc.pojo.User;
import cn.kgc.userprovider.service.UserService;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName RestUserServiceClient
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2020/12/13 10:47
 * @Version 1.0
 **/
@RestController
public class RestUserServiceClient {

    @Autowired
        UserService userService;


        @RequestMapping(value="checkpwd",method = RequestMethod.GET)
        public boolean loginByNP(@RequestParam("userCode") String userCode, @RequestParam("pwd") String userPssword){
            try {
                if(userService.checkUserByNamepwd(userCode, userPssword)>0){
                    return true;
                } else{
                    return false;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return  false;
        }



   // 对象入参，则请求方式必须是POST
    @RequestMapping(value="checkpwd2",method = RequestMethod.POST)
    public boolean loginByNP2(@RequestBody Map<String,String> map){
        try {
            if(userService.checkUserByNamepwd(map.get("userCode"), map.get("pwd"))>0){
                return true;
            } else{
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  false;
    }


    // 自定义对象入参，则请求方式必须是POST
    @RequestMapping(value="checkpwd3",method = RequestMethod.POST)
    public boolean loginByNP3(@RequestBody User user){
        try {
            if(userService.checkUserByNamepwd(user.getUserCode(), user.getUserPassword())>0){
                return true;
            } else{
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  false;
    }


    @PostMapping(value = "addUser")
    public Integer addUser(@RequestBody User user){
            return  userService.addUser(user);
    }



    @GetMapping(value = "/addUser")
    public void testRibbon(@RequestParam int num){
        System.out.println("添加第"+num+"个用户到数据库");
    }






}
